<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<!-- Header -->
<header data-am-widget="header"
	class="am-header am-header-default am-header-fixed">
	<div class="am-header-left am-header-nav">
		<a id="window-back" href="javascript:void(0)" data-am-offcanvas> <i
			class="am-icon-chevron-left"></i><span class="am-header-nav-title">修改密码</span>
		</a>
	</div>
	<h1 class="am-header-title"></h1>
</header>

<div style="height: 15px"></div>
<!-- main form -->
<div class="am-g">
	<div class="am-u-md-12 am-u-sm-centered">
		<form class="am-form my-form">
			<fieldset class="am-form-set">
				<div class="am-form-group">
					<input id="oldPwd" name="oldPwd" type="password" placeholder="旧密码"
						required>
				</div>
				<div class="am-form-group">
					<input id="newPwd" name="newPwd" type="password" placeholder="新密码"
						required>
				</div>
				<div class="am-form-group">
					<input name="repeatPwd" type="password" placeholder="重复密码"
						data-equal-to="#newPwd" data-validation-message="必须与输入密码相同" required>
				</div>
			</fieldset>
			<button id="modifyPwdBtn" type="button" class="am-btn am-btn-success am-btn-block">修改</button>
		</form>
	</div>
</div>

<script type="text/javascript">
	$(function() {
		$('.am-form')
				.validator(
						{
							onValid : function(validity) {
								$(validity.field).closest('.am-form-group')
										.find('.am-alert').hide();
							},

							onInValid : function(validity) {
								var $field = $(validity.field);
								var $group = $field.closest('.am-form-group');
								var $alert = $group.find('.am-alert');
								// 使用自定义的提示信息 或 插件内置的提示信息
								var msg = $field.data('validationMessage')
										|| this.getValidationMessage(validity);

								if (!$alert.length) {
									$alert = $(
											'<div class="am-alert am-alert-danger"></div>')
											.hide().appendTo($group);
								}

								$alert.html(msg).show();
							}
						});
		
		$('#modifyPwdBtn').click(function(){
			if($('.am-form').data('amui.validator').isFormValid()){
				$.post('mobile/modifyPwd', {
					oldPwd : $('#oldPwd').val(),
					newPwd: $('#newPwd').val()
				}, function(result) {
					if (result.code == 'ACK') {
						if(result.message == 'errorMsg'){
							showAlert(result.data);
						}else{
							showSuccessMsg(result.data, "mobile/selection");
						}
					}
				}, 'json');
			}
		});

	});
</script>